<extend name="./_base"/>
<block name="css">

</block>
<block name="header">

</block>
<block name="menu">

</block>
<block name="content">
    <article class="page-container">
        <div class="text-c mb-50">
            <h1>Kvv自动发货平台</h1>
            <small><span class="c-red" style="font-weight: 900">领取之后请立即使用</span></small>
        </div>
        <div class="text-c">
            <form class="Huiform" method="post" action="" target="_self">
                <input type="text" class="input-text" style="width:250px" placeholder="请输入手机号查看已领取的点卡" name="phone">
                <button type="button" class="btn btn-success" onclick="query()"><i class="Hui-iconfont">&#xe665;</i> 查询
                </button>
            </form>
        </div>

        <div class="cl pd-5 bg-1 bk-gray mt-20 mb-20">
                <span class="l">
                    <a href="javascript:;" onclick="getCard()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 提取点卡</a>
                </span>
        </div>
        <table id="card-list" class="table table-border table-bordered table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="9">领取列表</th>
            </tr>
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="" value=""></th>
                <th width="40">ID</th>
                <th width="40">领取者</th>
                <th width="120">手机号</th>
                <th width="60">游戏</th>
                <th width="120">游戏ID</th>
                <th width="120">卡号</th>
                <th width="150">密码</th>
                <th width="80">数量</th>
                <th width="80">价格</th>
                <th width="100">状态</th>
                <th width="100">领取时间</th>
            </tr>
            </thead>
        </table>
    </article>

</block>

<block name="script">
    <script src="__PUBLIC__/Lib/datatables/js/jquery.dataTables.js"></script>

    <script type="text/javascript">

        var table;
        function showTable(ext) {
            table=$('#card-list').on('xhr.dt',function (e, settings, json, xhr) {
                if (json.status===0){
                    layer.alert(json.info);
                }
            }).dataTable({
                order: [[1, 'desc']],
                processing: true,
                serverSide: true,
                ajax: {
                    url: '',
                    data:function (data) {
                        return $.extend(data,ext);
                    }
                },
                columns: [
                    {
                        data: 'id',
                        render: function (data) {
                            return '<input type="checkbox" name="id" value="' + data + '">'
                        },
                        className: 'text-c',
                        orderable: false
                    },
                    {
                        data: 'id',
                        className: 'text-c',
                    },
                    {data: 'uname'},
                    {data: 'uphone'},
                    {data: 'game'},
                    {data: 'game_id'},
                    {data: 'cno'},
                    {data: 'cpwd'},
                    {
                        data: 'amount', render: function (data) {
                        if (data >= 10000) {
                            return data / 10000 + ' 亿金币';
                        } else {
                            return data + ' 万金币';
                        }
                    }

                    },
                    {
                        data: 'price',
                        render: function (data) {
                            return data + ' 元';
                        }
                    },
                    {
                        data: 'status',
                        render: function (data, type, row, meta) {
                            var render;
                            switch (parseInt(data)) {
                                case 0:
                                    render = '<label class="label radius">待结算</label>';
                                    break;
                                case 1:
                                    render = '<label class="label label-success radius">已结算</label>';
                                    break;
                                default:
                                    render = '<label class="label label-danger radius">未知状态</label>';
                                    break;
                            }
                            return render;
                        },
                        className: 'text-c'
                    },
                    {data:'time'}
                ],
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "未找到数据",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }

                },
                destroy:true
            }).api()

        }
        function getCard() {
            layer_show('在线提卡', '{:U(getCard)}', 500, 500)
        }

        function query() {
            var phone = $("[name='phone']").val();
            $.ajax({
                type: 'GET',
                url: '{:U(Verify)}',
                data: {phone:phone},
                success: function (result) {
                    if (result.status == 1) {
                        layer.prompt({
                            title: '请输入手机验证码',
                            formType: 0, //输入框类型，支持0（文本）默认1（密码）2（多行文本）
                            value: '', //初始时的值，默认空字符
                            maxlength: 6 //可输入文本的最大长度，默认500
                        },function (value, index, elem) {
                            showTable({phone:phone,verify:value});
                            layer.close(index)
                        });
                    } else {
                        layer.alert(result.info, {icon: 5});
                    }
                },
                dataType: 'JSON'
            });
        }
    </script>

</block>
